def format_timedelta(delta):
    """
    start_time = datetime.now()
    end_time = datetime.now()
        time_diff = end_time - start_time
        logging.info(f"{video_file_name} 完成,耗时 {format_timedelta(time_diff)}")
    :param delta:
    :return:
    """
    total_seconds = delta.total_seconds()

    # 修改部分：处理小于1秒的情况（只显示最大的单位）
    if total_seconds < 1:
        if total_seconds >= 1e-3:  # >=1毫秒（0.001秒）
            return f"{total_seconds * 1000:.3f}毫秒"  # 保留3位小数，如 "11.454毫秒"
        elif total_seconds >= 1e-6:  # >=1微秒（0.000001秒）
            microseconds = int(total_seconds * 1e6)
            return f"{microseconds}微秒"
        else:  # <1微秒（纳秒级）
            nanoseconds = int(total_seconds * 1e9)
            return f"{nanoseconds}纳秒"

    # 定义时间单位
    intervals = (
        ("年", 60 * 60 * 24 * 365),
        ("个月", 60 * 60 * 24 * 30),
        ("周", 60 * 60 * 24 * 7),
        ("天", 60 * 60 * 24),
        ("小时", 60 * 60),
        ("分钟", 60),
        ("秒", 1),
    )

    result = []
    for name, seconds in intervals:
        value = int(total_seconds // seconds)
        if value > 0:
            total_seconds -= value * seconds
            result.append(f"{value}{name}")

    # 只显示最大的两个单位
    if len(result) > 2:
        result = result[:2]

    return " ".join(result)
